package com.ctg.payroll2.action.social;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.ctg.payroll2.bean.filter.social.PbSocialTypeFilter;
import com.ctg.payroll2.bean.po.social.PbSocialType;
import com.ctg.payroll2.service.social.PbSocialTypeService;
import com.ctg.payroll2.util.Constants;
import com.ctg.platform.util.Page;
import com.ctg.platform.util.Parse;
import com.opensymphony.xwork2.ActionSupport;
/**
 * 社保类别管理
 * @author 鲁力 2009-9-1 下午02:38:50
 *
 */
public class PbSocialTypeAction extends ActionSupport {
	private static final long serialVersionUID = 1144694792092748190L;
	/**
	 * 返回给页面的标记
	 */
	private int msg;
	/**
	 * 翻页结果
	 */
	private Page result;
	private List<PbSocialType> resultAll;	//不翻页按条件查询所有结果
	
	/**
	 * 查询条件
	 */
	private PbSocialTypeFilter filter;
	/**
	 * 编辑社保类别和新增社保类别的entity
	 */
	private PbSocialType pbSocialType;
	/**
	 * 用到的service,用spring注入
	 */
	private PbSocialTypeService pbSocialTypeService;
	private String typeIds;
	
	/**
	 * 点击页面查询按钮
	 * @return 翻页查询的结果
	 */
	public String QueryPbSocialTypeResult() {
		try {
			HttpServletRequest request = ServletActionContext.getRequest();
			if(filter==null){
				filter=new PbSocialTypeFilter();
			}
			filter.setStartIndex(Parse.toInteger(request.getParameter(Constants.START) , 0));
			filter.setEndIndex(Parse.toInteger(request.getParameter(Constants.LIMIT), Constants.DEFAULT_PAGE_SIZE));
			result = pbSocialTypeService.getPbSocialTypePageByFilter(filter);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	/**
	 * 下拉框使用
	 * @return 不翻页所有结果
	 */
	public String QueryPbSocialType() {
		try {
			if(filter==null){
				filter=new PbSocialTypeFilter();
			}
			filter.setValid("1");
			resultAll = pbSocialTypeService.getPbSocialTypeListByFilter(filter);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	
	/**
	 * 新增的action
	 * @return
	 */
	public String addPbSocialType() {
		pbSocialTypeService.insertPbSocialType(pbSocialType);
		return SUCCESS;
	}
	/**
	 * 复查pbSocialType,编辑时用到
	 * @return
	 */
	public String retrieveEntity() {
		pbSocialType = pbSocialTypeService.getPbSocialTypeById(pbSocialType.getSocial_typeid());
		return SUCCESS;
	}
	/**
	 * 判断是否已经存在了同名的PbSocialType,页面接受msg做判断,1表示重复,0表示不重复
	 * @return
	 */
	public String checkIsDuplicate(){
		pbSocialType = pbSocialTypeService.getPbSocialTypeByName(pbSocialType.getSocial_typename());
		msg=pbSocialType==null?1:0;
		return SUCCESS;
	}
	public String updatePbSocialType(){
		pbSocialTypeService.updatePbSocialType(pbSocialType);
		return SUCCESS;
	}
	private String delIds;
	private String updIds;
	public String deletePbSocialType(){
		pbSocialTypeService.deletePbSocialTypeByIds(delIds, updIds);
		return SUCCESS;
	}
	/**********************************************************
	 * 
	 * 以下是getter, setter方法
	 * 
	 *********************************************************/
	/**
	 * @return 返回filter
	 */
	public PbSocialTypeFilter getFilter() {
		return filter;
	}
	/**
	 * @param filter 设置filter
	 */
	public void setFilter(PbSocialTypeFilter filter) {
		this.filter = filter;
	}
	/**
	 * @return 返回pbSocialType
	 */
	public PbSocialType getPbSocialType() {
		return pbSocialType;
	}
	/**
	 * @param pbSocialType 设置pbSocialType
	 */
	public void setPbSocialType(PbSocialType pbSocialType) {
		this.pbSocialType = pbSocialType;
	}
	/**
	 * @return 返回result
	 */
	public Page getResult() {
		return result;
	}
	/**
	 * @param result 设置result
	 */
	public void setResult(Page result) {
		this.result = result;
	}
	/**
	 * @param pbSocialTypeService 设置pbSocialTypeService
	 */
	public void setPbSocialTypeService(PbSocialTypeService pbSocialTypeService) {
		this.pbSocialTypeService = pbSocialTypeService;
	}
	/**
	 * @return 返回msg
	 */
	public int getMsg() {
		return msg;
	}
	/**
	 * @param msg 设置msg
	 */
	public void setMsg(int msg) {
		this.msg = msg;
	}
	/**
	 * @return 返回typeIds
	 */
	public String getTypeIds() {
		return typeIds;
	}
	/**
	 * @param typeIds 设置typeIds
	 */
	public void setTypeIds(String typeIds) {
		this.typeIds = typeIds;
	}
	public List<PbSocialType> getResultAll() {
		return resultAll;
	}
	public void setResultAll(List<PbSocialType> resultAll) {
		this.resultAll = resultAll;
	}
	/**
	 * @return 返回delIds
	 */
	public String getDelIds() {
		return delIds;
	}
	/**
	 * @param delIds 设置delIds
	 */
	public void setDelIds(String delIds) {
		this.delIds = delIds;
	}
	/**
	 * @return 返回updIds
	 */
	public String getUpdIds() {
		return updIds;
	}
	/**
	 * @param updIds 设置updIds
	 */
	public void setUpdIds(String updIds) {
		this.updIds = updIds;
	}
}
